package com.wedjg.concurrency.example.singleton;

import com.wedjg.concurrency.annotations.Recommend;
import com.wedjg.concurrency.annotations.ThreadSafe;

/**
 * 枚举模式
 * 最安全
 * @author wedjg
 * @version 1.0
 * @date 2019/6/2
 */
@ThreadSafe
@Recommend
public class SingletonExample7 {

    public SingletonExample7() {
    }

    private static SingletonExample7 getInstance() {
        return Singleton.INSTANCE.getSingleton();
    }

    private enum Singleton {
        INSTANCE;

        private SingletonExample7 singleton;

        //JVM保证此方法只调用一次
        Singleton() {
            singleton = new SingletonExample7();
        }

        public SingletonExample7 getSingleton() {
            return singleton;
        }
    }


}
